package com.funtest.shard.controller;

import com.funtest.shard.database.dao.TOrderJpa;
import com.funtest.shard.database.dao.PersonJpa;
import com.funtest.shard.database.entity.Person;
import com.funtest.shard.database.entity.TOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: flathead
 * @Date: 2021/5/3 11:55
 */
@RestController
public class TestController {

    @Autowired
    TOrderJpa tOrderJpa;

    @Autowired
    PersonJpa personJpa;

    @GetMapping(value = "saveOrder")
    public String saveOrder() {
        for (Long i = 0L; i < 10L; i++) {
            TOrder TOrder = new TOrder();
            TOrder.setOrderId(i);
            TOrder.setUserId(i);
            tOrderJpa.save(TOrder);
        }
        return "success";
    }

    @GetMapping(value = "savePersons")
    public String savePersons() {
        for (Long i = 0L; i < 10L; i++) {
            Person person = new Person();
            person.setPersonId(i);
            person.setPersonName(i);
            personJpa.save(person);
        }
        return "success";
    }

    @GetMapping(value = "getAllOrders")
    public List<TOrder> getAllOrders() {
        return tOrderJpa.findAll();
    }
}
